<!-- #include file="includes/sessao.asp" -->
<!-- #include file="includes/styles.css" -->
<!-- #include file="includes/conn.asp" -->
<html>
<head>
<title>Solic</title>
<script>
function Validacao(f){
    if (f.cmb_setor.value==""){
        alert('Selecione o setor');
        f.cmb_setor.focus();
        return;
    }
    if (f.cmb_colaborador.value==""){
        alert('Selecione o colaborador');
        f.cmb_colaborador.focus();
        return;
    }
    if (confirm("Confirma o cadastramento do gerente?")) {
        f.submit();
    }
}
</script>
</head>
<body>
<table width="780" border="0" cellspacing="0" cellpadding="1"><tr><td>
<center>
    <strong>Gerentes</strong>
    <hr width="80%" size="3">
    <form method="post" action="gerente.asp">
    <p>Setores:<br><select name="cmb_setor"><option value="">SELECIONE</option>	
<%
  on error resume next
  if request("cmb_colaborador") <> "" then
	conn.execute "insert into gerente(cod_setor,cod_colaborador) values(" & request("cmb_setor") & "," & request("cmb_colaborador") & ")"  
  end if
  if request("cd") <> "" then
	conn.execute "delete from gerente where cod_colaborador = " & request("cd")
  end if

  Dim consulta
  set rs = server.createObject("adodb.recordset")
  consulta = "select * from setor where (stid NOT IN (select cod_setor from gerente)) order by stnome"
  rs.open consulta,conn,3,3
  while not rs.eof  
    response.write("<option value='" & rs("stid") & "'>" & rs("stnome") & " - " & rs("stsigla") & "</option>")
	rs.movenext	
  wend
%>
      </select></p>
    <p>Colaboradores:<br><select name="cmb_colaborador"><option value="">SELECIONE</option>
<%
  rs.close
  consulta = "select usid,usnome from usuario where (usid not in (select cod_colaborador from gerente)) order by usnome"
  rs.open consulta,conn,3,3
  while not rs.eof  
    response.write("<option value='" & rs("usid") & "'>" & 	rs("usnome") & "</option>")
	rs.movenext
  wend
%>
    </select></p>
    <p><input type="button" value="Enviar" onClick="Validacao(this.form)">
    </form>
    <hr width="80%" size="3">   
    <strong>Gerentes Cadastrados</strong><br><br>
    <table border="1" width="90%">
<%
  rs.close
  consulta = "SELECT dbo.Gerente.Cod_Colaborador, dbo.Setor.STSIGLA, dbo.Usuario.USNOME FROM dbo.Setor INNER JOIN dbo.Gerente ON dbo.Setor.STID " &_
             "= dbo.Gerente.Cod_Setor INNER JOIN dbo.Usuario ON dbo.Gerente.Cod_Colaborador = dbo.Usuario.USID"
  rs.open consulta,conn,3,3
  while not rs.eof  
%>
 <tr align="center">
   <td width="30%"><%=rs("stsigla")%></td>
   <td width="65%"><%=rs("usnome")%></td>
   <td width="10%"><a href="gerente.asp?cd=<%=rs("cod_colaborador")%>"><img src="imagens/excluir.gif" border="0" alt="Remove"></a></td></tr>
<%
	rs.movenext
  wend
%>
</table>
</center>
</td></tr></table>
</body>
</html>